package com.example.gateway.config;

import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.Set;

/*
@author SupUncleBlack
@date 2021/8/30 - 15:40
*/
@Configuration
public class GatewayConfiguration {

    /*
    * 配置限流规则
    */
    @PostConstruct
    private void initGatewayRules(){
        Set<GatewayFlowRule> rules = new HashSet<>();
        rules.add(new GatewayFlowRule("customer")
            .setCount(1)    //限流阈值
            .setIntervalSec(1)  //统计时间窗口，单位是秒
        );
        GatewayRuleManager.loadRules(rules);
    }
}
